let request = {};

axios.interceptors.response.use(res => {
　　return res.data;
})

axios.interceptors.request.use(config => {
	const token = localStorage.getItem(settings.token) || ""
	if (token) {
	  config.headers['Access-Token'] = token
	}
	config.headers['systemNo'] = settings.systemNo
　　return config;
})

request.get = async function(config) {
	let result
	let url = config["url"];
	let data = config['data'];
	let server = config['server']
	if(!url){
		mui.toast("请求后台地址不能为空");
		return false;
	}
	if(!data){
		data = {};
	}
	if(!server){
		server = settings.devServer;
	}
	await axios.get(settings.devServer+url,{
			params: data,
			timeout:30000,
		})
		.then(res => {
			result = res;
		})
		.catch(err => {
			console.error(err);
			result = {success:false,message:err}
		})
	return result
}

request.post = async function(config) {
	let result
	let url = config["url"];
	let data = config['data'];
	let server = config['server']
	if(!url){
		mui.toast("请求后台地址不能为空");
		return false;
	}
	if(!data){
		data = {};
	}
	if(!server){
		server = settings.devServer;
	}

	await axios.post(server+url,data,{
			timeout:30000,
		})
		.then(res => {
			result = res;
			
		})
		.catch(err => {
			console.error(err);
			result = {success:false,message:err}
		})
	return result
	
}

